package com.briup.web;

import com.briup.entity.Emp;
import com.briup.service.IEmpService;
import com.briup.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/emps")
public class EmpController {
    //业务层对象
    @Autowired
    private IEmpService empService;

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        System.out.println("in web, id: " + id);
        Emp emp = empService.getById(id);

        return Result.success(emp);
    }
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        empService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/insert")
    public Result insert(Emp emp) {
        emp.setId(1);
        emp.setName("宋勇");
        emp.setUsername("songyong");
        emp.setPassword("123456");
        emp.setGender((short) 1);
        emp.setJob((short) 1);
        emp.setDeptId(1);
        emp.setImage("1.jpg");
        emp.setEntrydate(java.time.LocalDate.now());
        emp.setCreateTime(java.time.LocalDateTime.now());
        emp.setUpdateTime(java.time.LocalDateTime.now());
        empService.insert(emp);
        return Result.success();
    }
}
